home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 …SCII & the Runetime Code / ADC Developer CD (1992-07) (''Butch ASCII And The Runtime Code'')_iso / Dev.CD 199207.iso / Tools & Apps / Devices & Hardware / A⁄ROSE / MultiThread / MultiThread.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-21  |  3.0 KB  |  137 lines  |  [TEXT/MPS ]

  1. /*
  2.     Header file for multi thread Macintosh task
  3.     
  4.     You can call CreateQueue to get a pointer to data structure for the queue
  5.     
  6.     You can call all A/ROSE routines through this structure
  7.     
  8.     You can call DestroyQueue to get rid of this structure
  9.     
  10.     Written by:    Anumele D. Raja
  11.     
  12.     Date:        March 19, 1991
  13.     
  14.     Copyright @ Apple Computer, Inc.  1991
  15.     
  16. */
  17.  
  18. #ifndef    __TYPES__
  19. #include    <Types.h>
  20. #endif
  21.  
  22. #ifndef    __RESOURCES__
  23. #include    <Resources.h>
  24. #endif
  25.  
  26. #ifndef __MEMORY__
  27. #include    <Memory.h>
  28. #endif
  29.  
  30. #ifndef    _os_defined_
  31. #include    "os.h"
  32. #endif
  33.  
  34. struct QueueEntry {
  35.         Handle            rsrcHandle;            // Reserved area
  36.         void            (*CloseQueue)(void);
  37.         void            (*FreeMsg)(mMessage *msgPtr);
  38.         char            (*GetCard)(void);
  39.         unsigned long    (*GetETick)(void);
  40.         tid_type        (*GetICCTID)(void);
  41.         struct IPCg        *(*GetIPCg)(void);
  42.         mMessage        *(*GetMsg)(void);
  43.         tid_type        (*GetNameTID)(void);
  44.         unsigned short    (*GetTickPS)(void);
  45.         tid_type        (*GetTID)(void);
  46.         short            (*IsLocal)(char *address);
  47.         void            (*KillReceive)(void);
  48.         short            (*LockRealArea)(void *virtualAddr, unsigned long length,
  49.                                 struct addressareas buffer[], unsigned long count);
  50.         tid_type        (*Lookup_Task)(char *object, char *type, tid_type nm_TID,
  51.                                             unsigned short *index);
  52.         short            (*NetCopy)(tid_type srcTID, void *srcAddress,
  53.                                     tid_type dstTID, void *dstAddress,
  54.                                             unsigned long byteCount);
  55.         tid_type        (*OpenQueue)(void (*UserProcedure)(void));
  56.         mMessage        *(*Receive)(unsigned long mID, tid_type mFrom,
  57.                                         unsigned short mCode, long timeOut,
  58.                                         void (*CompletionRoutine)(mMessage *));
  59.         char            (*Register_Task)(char object[], char type[], short local_only);
  60.         void            (*Send)(mMessage *msgPtr);
  61.         void            (*SwapTID)(mMessage *msgPtr);
  62.         void            (*UnLockRealArea)(void *virtualAddr, unsigned long length);
  63. };
  64.  
  65. #ifndef __cplusplus
  66. typedef struct QueueEntry QueueEntry;
  67. #endif
  68.  
  69. //  Routine that reads in the MultiThread resource and returns a pointer
  70.  
  71. /*
  72.     Usage:
  73.     
  74.     In this program you are operating on another queue in addition to the
  75.         queue you get with plain OpenQueue
  76.     
  77.     QueueEntry *queuePtr;
  78.     
  79.     if (queuePtr = CreateQueue()) {
  80.         // Queue is ok
  81.         
  82.         mMessage *mspPtr;
  83.         tid_type    myTID;
  84.         
  85.         myTID = queuePtr->OpenQueue();
  86.         msgPtr = quueuePtr->GetMsg();
  87.         .
  88.         .
  89.         .
  90.         queuePtr->Send(msgPtr);
  91.         .
  92.         .
  93.         .
  94.         msgPtr = queuePtr->Receive(OS_MATCH_ALL, myTID, OS_MATCH_ALL, -1, 0);
  95.         .
  96.         .
  97.         .
  98.         DestroyQueue(queuePtr);
  99.         .
  100.         .
  101.         .
  102. */
  103.  
  104. const kRsrcType = 'mlti';
  105. const char kRsrcName[] = "\PMultiThread";
  106.  
  107. QueueEntry *CreateQueue()
  108. {
  109.     Handle         multiHdl;
  110.     QueueEntry     *qPtr;
  111.     void         *(*GetPtr)(void);
  112.     
  113.     if ((multiHdl = GetNamedResource(kRsrcType, kRsrcName)) == 0)
  114.         return 0;
  115.     
  116.     DetachResource(multiHdl);        // Delink the handle from resource
  117.  
  118.     MoveHHi(multiHdl);        // Move it to high memory ready for locking
  119.     
  120.     HLock(multiHdl);
  121.     
  122.     GetPtr = (void *)*multiHdl;
  123.     qPtr = (QueueEntry     *)StripAddress(GetPtr());
  124.     qPtr->rsrcHandle = multiHdl;            // save the handle
  125.     return qPtr;
  126. }
  127.  
  128. void DestroyQueue(QueueEntry *qPtr)
  129. {
  130.     Handle multiHdl;
  131.     
  132.     multiHdl = qPtr->rsrcHandle;
  133.     
  134.     HUnlock(multiHdl);
  135.     DisposHandle(multiHdl);
  136. }
  137.